<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>添加员工页面</h1>
<form action="">
    <input type="text" name="name" placeholder="员工姓名">
    <input type="text" name="job" placeholder="员工工作">
    <input type="text" name="age" placeholder="员工年龄">
    <input type="text" name="salary" placeholder="员工工资">
    <input type="button" value="添加" @click="insert()">
</form>
<!--引入axios和vue-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

<script>
    let v = new Vue({
        el:"form",
        data:{
            
        },
        methods:{
            insert:function () {
                //form表单里的数据
                let data = new FormData(document.querySelector("form"));
                //发请求
                axios.post("/insert",data).then(function () {
                    alert("添加成功!")
                    location.href = "/"; //跳转回首页
                })
            }
        }
    })
</script>
</body>
</html>